#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：turbo
@File    ：renderers.py
@Author  ：赵加响
@Date    ：2024/1/10 17:57 
@Desc    ：适配DRF浏览器API渲染器
"""
from rest_framework.renderers import BrowsableAPIRenderer


class CustomBrowsableAPIRenderer(BrowsableAPIRenderer):
    """
    自定义浏览器API渲染器，解决封装SuccessResponse引发的Raw Data和Html form不显示数据问题
    """

    def get_rendered_html_form(self, data, view, method, request):
        if 'data' in data:
            data = data['data']
        return super().get_rendered_html_form(data, view, method, request)

    def get_raw_data_form(self, data, view, method, request):
        if 'data' in data:
            data = data['data']
        return super().get_raw_data_form(data, view, method, request)
